<?php
namespace Shopmodule\Controller;
use Think\Controller;
class ExtendController extends Controller {
	public $login;
	public $c;
	public $MixedNick;
	public $UserAvatar;
	public $UserPic;
	public function  __construct (){
		parent::__construct();
		// $jssdkService->init($appKey,$secret);
		$this->sid = (int)I("get.shop_id");
		$this->module_width = (int)I("get.module_width");
		$this->seller_nick = I("get.seller_nick");
		$this->top_parameters = I("get.top_parameters");
		$this->top_sign =  I("get.top_sign");
		$this->top_appkey =  I("get.top_appkey")?I("get.top_appkey"):C("SM_KEY");
		$this->top_session =  I("get.top_session");
		// if(!$this->module_width){
			// echo 'error with module_width';
			// die();
		// }
		$mysign = base64_encode(md5($this->top_appkey.$this->top_parameters.$_GET["top_session"]."1671fcc6a8ff1ffdf73459fbc84841f6",true));
		// if($mysign != $this->top_sign){
		// //加密结果本地环境乱码，线上环境正常。
			// echo '本活动仅在店铺内访问！';
		// }
		Vendor('taobaosdk.top.TopClient');
		Vendor('taobaosdk.lotusphp_runtime.Logger.Logger');
		Vendor('taobaosdk.top.RequestCheckUtil');
		$this->c =  new \TopClient();
		$this->c->appkey=C("APPKEY");
		$this->c->secretKey=C("APPSECRET");
		// if($context->getBrowser()){
			// $browser = $context->getBrowser();
			// $this->MixedNick = $browser->getMixNick();// $browser->nick;
		// }
		// if(APP_DEBUG){
			// $this->MixedNick = "k01UulQpdrfWP/FlNTAiJ3nWf8p4y2Nzgo7UGObn3+dFq0=2343234234";
		// }
		// $User = M("User");
		// $this->UserUZID = $User->where("`mixednick`='".$this->MixedNick."'")->getField("id");
		// if(!$this->UserUZID){
			// $data["mixednick"]=$this->MixedNick;
			// $data["jointime"]=date("Y-m-d H:i:s",time());
			// $this->UserUZID = $User->add($data);
		// }
		$this->safe = substr(md5($this->top_sign),0,6);
		$this->UserAvatar = "http://xl.uz.taobao.com/sd/getAvatar.do?encryptednick=".urlencode($this->MixedNick);
		$this->UserPic = "http://xl.uz.taobao.com/_RS/user/picture?mixUserNick=".urlencode($this->MixedNick);
		if($cacheService){
			$this->assign('tae',true);
		}
		$this->assign('top_session',$this->top_session);
		$this->assign('top_appkey',$this->top_appkey);
		$this->assign('top_parameters',$this->top_parameters);
		$this->assign('top_sign',$this->top_sign);
		$this->assign('sid',$this->sid);
		$this->assign('module_width',$this->module_width);
		$this->assign('seller_nick',$this->seller_nick);
		$this->assign('uavatar',$this->UserAvatar);
		$this->assign('upic',$this->UserPic);
		$this->assign('top',date(w)>0?(32+(42*(date(w)-1))):284);
	}
	public function __destruct(){
		unset($this->c);
	}
	public function ajaxReturn($reda){
		$reda = json_encode($reda);
		$re = I("get.callback")?I("get.callback").'('.$reda.')':$reda;
		parent::ajaxReturn($re);
	}
}